package cn.fl.system.service.impl;

import java.util.List;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import cmm.mid.core.framework.page.Pager;
import cn.cmm.base.framework.constant.BaseExceptionConstant;
import cn.cmm.base.framework.exception.BaseException;
import cn.cmm.base.framework.utils.BaseLogUtils;
import cn.cmm.base.framework.utils.CollectionUtils;
import cn.cmm.base.framework.utils.StringUtils;
import cn.fl.framework.base.context.CurrentThreadContext;
import cn.fl.system.api.ISysInsTabCfgApiService;
import cn.fl.system.condition.SysInsTabCfgQueryCondition;
import cn.fl.system.dto.SysInsTabCfgDTO;
import cn.fl.system.service.ISysInsTabCfgService;
import cn.fl.system.transform.SysInsTabCfgVOTransform;
import cn.fl.system.vo.SysInsTabCfgVO;

/**
 * @Description: 资管机构模块配置 客户端服务层接口实现
 * @Description: 业务层方法名称前缀：新增：add* 删除：remove* 修改：modify* 查询对象：select* get*
 *               批量：batch* 查询集合：search*
 */
@Service
public class SysInsTabCfgServiceImpl implements ISysInsTabCfgService {

	/**
	 * 日志
	 */
	private static final Logger logger = LoggerFactory.getLogger(SysInsTabCfgServiceImpl.class);

	/**
	 * 自定义 API 自行注入需要的API服务
	 */
	@Autowired
	private ISysInsTabCfgApiService sysInsTabCfgApiService;

	@Override
	public SysInsTabCfgVO selectById(Long id) throws BaseException {
		if (StringUtils.isEmpty(id)) {
			BaseLogUtils.info(logger, "selectById", "主键参数不能为空!", CurrentThreadContext.getCurrentUserName());
			throw new BaseException(BaseExceptionConstant.BASE_EXCEPTION_CODE_600, "获取对象主键不能为空!");
		}
		SysInsTabCfgDTO dto = this.sysInsTabCfgApiService.selectById(id);
		return SysInsTabCfgVOTransform.toVO(dto);
	}

	/**
	 * 获取唯一对象
	 */
	@Override
	public SysInsTabCfgVO selectByInsCode(String insCode) throws BaseException {
		SysInsTabCfgDTO dto = this.sysInsTabCfgApiService.selectByInsCode(insCode, CurrentThreadContext.getCurrentSysCd());
		if(dto != null) {
			return SysInsTabCfgVOTransform.toVO(dto);
		}
		return null;
	}

	@Override
	public Pager searchListPage(Pager page) throws BaseException {
		if (null == page) {
			page = new Pager();
		}
		return this.sysInsTabCfgApiService.searchSysInsTabCfgListPage(page);
	}

	@Override
	public List<SysInsTabCfgVO> searchList(SysInsTabCfgQueryCondition sysInsTabCfgQueryConditoin) throws BaseException {
		List<SysInsTabCfgDTO> sysInsTabCfgDTOList = this.sysInsTabCfgApiService.searchList(sysInsTabCfgQueryConditoin);
		return SysInsTabCfgVOTransform.toVOList(sysInsTabCfgDTOList);
	}

}
